package com.wfm.threads;

import java.util.concurrent.*;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class PrintABCUsingCompletableFuture {
    public static void main(String[] args) {

        // 创建一个固定大小为3的线程池
        ExecutorService executor = Executors.newFixedThreadPool(3);

        // 定义打印次数
        int times = 10;

        // 初始 CompletableFuture
        CompletableFuture<Void> future = CompletableFuture.completedFuture(null);

        for (int i = 0; i < times; i++) {
            // 打印 "a"
            future = future.thenRunAsync(() -> System.out.println(Thread.currentThread().getName()+"--a"), executor)
                    // 打印 "b"
                    .thenRunAsync(() -> System.out.println(Thread.currentThread().getName()+"--b"), executor)
                    // 打印 "c"
                    .thenRunAsync(() -> System.out.println(Thread.currentThread().getName()+"--c"), executor);
        }

        // 等待所有任务完成
        future.join();

        // 关闭线程池
        executor.shutdown();
    }
}